﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ColemanSoftware.Delicious.Modules.Data;
using NUnit.Framework;

namespace Delicious.Modules.UnitTests
{
    [TestFixture]
    public class RequestorTests
    {
        IRequestor _requestor;

        [SetUp]
        public void Init()
        {
            _requestor = new Requestor();
        }


        [Test]
        public void Test1_GetRecentBookmarks()
        {
            _requestor = new Requestor();
            string results = _requestor.GetRecentBookmarks();

            PrintResults(results);

            Assert.IsTrue(results.Contains("errors") == false);
        }

        [Test]
        public void Test2_AddBookmark()
        {
            List<Tag> tags = new List<Tag>();
            tags.Add(new Tag()
            {
                Name = "Google",
                Value = "Google"
            });
            string results = _requestor.AddBookmark("Test BookmarkAdd", "Tetsing new tool", "http://google.com", tags);
            PrintResults(results);

            Assert.IsTrue(results.Contains("errors") == false);

        }

        [Test]
        public void Test3_UpdateBookmark()
        {
            var resquest = _requestor.UpdateBookmark("http://google.com", null, "Test Update Bookmark", "Google Update");
            Assert.IsTrue(resquest.Contains("errors") != true);
            PrintResults(resquest);
        }

        [Test]
        public void Test4_DeleteBookmark()
        {
            string results = _requestor.DeleteBookmark("http://google.com");
            PrintResults(results);

            Assert.IsTrue(!String.IsNullOrEmpty(results));
        }

        [Test]
        public void Test5_GetBookmarkByDate()
        {
            var results = _requestor.GetBookmarkByDate("12/24/2012");
            PrintResults(results);
        }

        [Test]
        public void Test6_GetBookmarkByUrl()
        {
            string badResults = _requestor.GetBookmarkByUri(new Uri("http://google.com"));
            string happyResults = _requestor.GetBookmarkByUri(new Uri("http://msdn.microsoft.com/en-us/library/sz6zd40f(v=vs.80).aspx"));
            Assert.IsTrue(happyResults.Contains("errors") == false);
        }

        [Test]
        public void Test7_GetBookmarkByTag()
        {
            string results = _requestor.GetBookmarkByTag("google");
            Assert.IsTrue(results.Contains("errors") == false);
        }

        [TearDown]
        public void Destroy()
        {
            _requestor = null;
        }

        private void PrintResults(object results)
        {
            if (results != null)
                System.Diagnostics.Debug.WriteLine(results);

            else
                System.Diagnostics.Debug.WriteLine("Code Succeeded: Null results");
        }
    }
}
